#define _CRT_SECURE_NO_WARNINGS 1
#include "myqueue.h"
MyQueue* myQueueCreate() {
    MyQueue* obj = (MyQueue*)malloc(sizeof(MyQueue));
    StackInit(&(obj->a));
    StackInit(&(obj->b));
    return obj;
}

void myQueuePush(MyQueue* obj, int x) {
    while (StackSize(&(obj->b)) > 0)
    {
        StackPush(&(obj->a), StackTop(&(obj->b)));
        StackPop(&(obj->b));
    }
    StackPush(&(obj->a), x);
}

int myQueuePop(MyQueue* obj) {
    while (StackSize(&(obj->a)) > 1)
    {
        StackPush(&(obj->b), StackTop(&(obj->a)));
        StackPop(&(obj->a));
    }
    int jg = StackTop(&(obj->a));
    StackPop(&(obj->a));
    return jg;
}

//int myQueuePeek(MyQueue* obj) {
//    while (StackSize(&(obj->b)) > 0)
//    {
//        StackPush(&(obj->a), StackTop(&(obj->b)));
//        StackPop(&(obj->b));
//    }
//    MyQueue* peek = obj;
//    while (StackSize(&(peek->a)) > 1)
//    {
//        StackPush(&(peek->b), StackTop(&(peek->a)));
//        StackPop(&(peek->a));
//    }
//    return StackTop(&(peek->a));
//}

int myQueuePeek(MyQueue* obj) {
    while (StackSize(&(obj->b)) > 0)
    {
        StackPush(&(obj->a), StackTop(&(obj->b)));
        StackPop(&(obj->b));
    }
    MyQueue peek = *obj;
    while (StackSize(&(peek.a)) > 1)
    {
        StackPush(&(peek.b), StackTop(&(peek.a)));
        StackPop(&(peek.a));
    }
    return StackTop(&(peek.a));
}

bool myQueueEmpty(MyQueue* obj) {
    if ((StackEmpty(&(obj->a)) == 1) && (StackEmpty(&(obj->b)) == 1))
    {
        return true;
    }
    else
    {
        return false;
    }
}

void myQueueFree(MyQueue* obj) {
    StackDestroy(&(obj->a));
    StackDestroy(&(obj->b));
    free(obj);
}